package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.po.GroupUserPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface GroupUserMapper extends JpaRepository<GroupUserPO, Long>, JpaSpecificationExecutor<GroupUserPO> {
    @Query(value = "select p from GroupUserPO p where p.groupId = :groupId and p.userId = :userId")
    GroupUserPO findByGroupAndUser(long groupId, long userId);

    @Query(value = "select p.userId from GroupUserPO p where p.groupId = :groupId")
    Collection<Long> findUserIdsByGroup(long groupId);

    @Query(value = "select p.groupId from GroupUserPO p where p.userId = :userId")
    Collection<Long> findGroupIdsByUser(long userId);
}
